<html>

<head>

<?php

ini_set("memory_limit","256M");
ini_set("max_execution_time","600");
$time_start = microtime(true);
include "../includes/constants.php";
include "../includes/db_schema.php";

$file_dir = "";					// needs / at the end if anything other than the current directory
$file_name = "spells_us.txt";
$table = "spells_us";

?>

<title></title>

</head>

<body>

<?php

if (file_exists($file_dir . $file_name) && is_readable($file_dir . $file_name)) {

	$Lines = file($file_dir . $file_name);

	CreateTableSchema($table);

	foreach($Lines as $key => $value) {
		$Data[$key] = explode("^", $value);
		if (!$fields_max) $fields_max = count($Data[$key]) - 1;
		// Get table structure if not already defined
		if (!$columns) {
			for ($x = 0; $x <= $fields_max; $x++) {
				$columns .= $Schema[$table][$x][COLUMN_NAME];
				if ($x != $fields_max) $columns .= ", ";
			};
		};
		unset($values);
		for ($x = 0; $x <= $fields_max; $x++) {
			$values .= "'" . addslashes($Data[$key][$x]) . "'";
			if ($x != $fields_max) $values .= ", ";
		};
		$query = "INSERT INTO " . $table . " (" . $columns . ") VALUES (" . $values . ")";
		global $db;
		echo $Data[$key][0] . ": " . $Data[$key][1];
//		if (@mysql_query($query,$db)) {echo " -- <font color=\"blue\">Successful</font>!";}
//		else {
//			echo " -- <font color=\"red\">Failed</font>! ";
//			echo "(" . mysql_error() . ")";
			echo " -- [<font color=\"Silver\">" . $query . "</font>]";
//		};
		echo "<br>\n";
		flush(); ob_flush();
	};

} else {
	echo "Unable to read " . $file_dir . $file_name;
};

include "../includes/footer.php";

?>

</body>

</html>